#ifndef MYTABLEMODEL_H
#define MYTABLEMODEL_H

#include <QAbstractTableModel>
#include "eigenhelper.h"

class MyTableModel : public QAbstractTableModel {
Q_OBJECT

public:
    MyTableModel(QObject *parent = nullptr);

    Q_INVOKABLE bool setFromEigen(const Eigen::VectorXd &x, const Eigen::VectorXd &y);

    Q_INVOKABLE bool setFromStd(const std::vector<double> &x, const std::vector<double> &y);

    Q_INVOKABLE bool setFromQVector(const QVector<double> &x, const QVector<double> &y);

    Q_INVOKABLE bool setFromCsv(const QString &path, size_t x_col = 0, size_t y_col = 1);

    Q_INVOKABLE int rowCount(const QModelIndex &index = QModelIndex()) const override;

    Q_INVOKABLE int columnCount(const QModelIndex &index = QModelIndex()) const override;

    Q_INVOKABLE Qt::ItemFlags flags(const QModelIndex &index) const;

    Q_INVOKABLE QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;

    Q_INVOKABLE bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;

    Q_INVOKABLE QVariant
    headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;

    Q_INVOKABLE bool
    setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);


    Q_INVOKABLE double xMin() const;

    Q_INVOKABLE double yMin() const;

    Q_INVOKABLE double xMax() const;

    Q_INVOKABLE double yMax() const;

    Q_INVOKABLE QVector<double> &getX();

    Q_INVOKABLE QVector<double> &getY();


private:
    void setMinMax();

    double m_xMin, m_yMin, m_xMax, m_yMax;
    QStringList m_header;
    QVector<double> m_x;
    QVector<double> m_y;

};

#endif // MYTABLEMODEL_H
